<?php
include('../conn.php');
require('../../tool/UpFileTool.class.php');

// 需传参数 
$ordersid=$_REQUEST['ordersid'];
$user_comment = $_REQUEST['user_comment'];
$user_images = $_FILES['user_images'];
// 需传参数 end

// 状态
$state4 = 4;
// 状态 end

if ($ordersid != '') {

	// 查找订单信息 
	$query = mysql_query("select state from goodsorders where ordersid=".$ordersid);
	$goodsorders = mysql_fetch_assoc($query);
	$orderstate = $goodsorders['state'];
	$type = $goodsorders['type'];
	// 查找订单信息 end

	$flag = true;
	$query = mysql_query("UPDATE goodsorders set state=".$state4." where ordersid=".$ordersid);
	if (mysql_affected_rows()<=0) {
		$flag = false;
	}

	if ($type == 0) { // 海淘
		// 上传照片
		if ($user_images['name'][0] != '') {
			$UpFileTool = new UpFileTool('user_images');
			$UpFileTool->multiImage($w=500, $h=500 ,$sumbimage='../../sumbimage', $srcimage='../../srcimage');
			$user_images = $UpFileTool->multiSumbImage;
			$user_srcimages = $UpFileTool->multiSrcImage;
		}
		// 上传照片 end
		$query = mysql_query("INSERT INTO tuihuo (ordersid,orderstate,user_comment,user_images,user_srcimages) VALUES ('".$ordersid."',".$orderstate.",'".$user_comment."','".$user_images."','".$user_srcimages."')");
		$id = mysql_insert_id();

		if (mysql_affected_rows()<=0) {
			$flag = false;
		}
	}elseif ($type == 1) { // 快购

		$query = mysql_query("INSERT INTO tuihuo (ordersid,orderstate) VALUES (".$ordersid.",".$orderstate.")");
		$id = mysql_insert_id();

		if (mysql_affected_rows()<=0) {
			$flag = false;
		}
	}

	if ($flag) {
		$arr = array('code' => 200, 'msg' => '申请成功', 'id' => $id);
	}else{
		$arr = array('code' => 201, 'msg' => '未更改数据');
	}

	// 调用信息推送接口
	$url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state4."&ordersid=".$ordersid;
	file_get_contents($url);
	// 调用信息推送接口 end


}else{
	$arr = array('code' => 400, 'msg' => 'ordersid或type(0为海淘，1为快购)不存在,为快购时可传参数：user_images,user_comment');
}

echo json_encode($arr);


